package com.newland.boss1.zxy;

import org.apache.servicecomb.provider.pojo.RpcReference;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author : zhangxuyuan
 * @Project: servicecombexample
 * @Package com.newland.boss1.zxy
 * @date Date : 2021年02月20日 15:39
 */
@RestController
public class ConsumerController {
    //rpc方式调用，类似dubbo
    @RpcReference(microserviceName = "provider",schemaId = "helloworldRpc")
    private HelloWorldEndPoint helloWorldEndPoint;

    //rest方式调用
    private RestTemplate restTemplate= RestTemplateBuilder.create();

    @GetMapping("/rpcHello")
    public String helloworld()
    {
        return helloWorldEndPoint.sayHello("testname");
    }

    @GetMapping("/restHello")
    public String restHello()
    {
        //url   cse://provider/sayhello?name=testname
        ResponseEntity<String> forEntity =
                restTemplate.getForEntity("cse://provider/sayhello?name="+"testname", String.class);
        return forEntity.getBody();
    }
}
